package net.qiqb.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import net.qiqb.core.domain.event.DomainEvent;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

@Slf4j
public class DomainEventReceiver {

    private ApplicationContext applicationContext;

    @RabbitListener(queues = "#{queueNameGenerator.generateQueueName()}")
    public void process(DomainEvent domainEvent) {
        log.info("rabbit 事件监听");
        applicationContext.publishEvent(domainEvent.getPayload());
        // 发送完后，需要返回一个ack确认，如果确认了没问题，表示这次请求OK了
        //rabbitTemplate.convertAndSend("domain-event-ask",domainEvent.getId());
    }

    @Autowired
    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }
}
